from django.test import TestCase

class XinHuaAPITests(TestCase):

    def setUp(self):
        print("=====Test XINHUA API ========")
        self.token = "b645626e4f6c11e9a725e0d55eb04500"

    def test_xinhuanews(self):
        number = 4
        res = self.client.get(
            '/xinhuanews',
            {
                'amount': number
            }
        )

        self.assertEqual(200, res.status_code)

        result = res.json()
        self.assertFalse(result['is_error'])
        self.assertEqual(number, len(result['data']))

        category = '01'
        res = self.client.get(
            '/xinhuanews',
            {
                'category': category
            }
        )

        self.assertEqual(200, res.status_code)

        result = res.json()
        self.assertFalse(result['is_error'])


